package com.mabs.ground.client;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.mabs.ground.client.common.AppActivityMapper;
import com.mabs.ground.client.common.AppPlaceHistoryMapper;
import com.mabs.ground.client.common.ClientFactory;
import com.mabs.ground.client.module.connexion.place.ConnexionPlace;
import com.mabs.ground.client.module.mod1.place.HelloPlace;
import com.mabs.ground.client.module.mod2.place.GoodbyePlace;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Example implements EntryPoint {
	ClientFactory clientFactory = GWT.create(ClientFactory.class);
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad()
	{
		// Start ActivityManager for the main widget with our ActivityMapper
		ActivityMapper activityMapper = new AppActivityMapper(clientFactory);
		ActivityManager activityManager = new ActivityManager(activityMapper, clientFactory.getEventBus());
		activityManager.setDisplay(new SimplePanel());
		
		// Start PlaceHistoryHandler with our PlaceHistoryMapper
		AppPlaceHistoryMapper historyMapper= GWT.create(AppPlaceHistoryMapper.class);
		PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
		historyHandler.register(clientFactory.getPlaceController(), clientFactory.getEventBus(), new HelloPlace("World!"));

		RootPanel.get().add(clientFactory.getMain());
		genererMenu();
		// Goes to place represented on URL or default place
		historyHandler.handleCurrentHistory();
	}	
	public void genererMenu(){
		clientFactory.getMain().addNavPlace( new HelloPlace("Hello"));
		clientFactory.getMain().addNavPlace( new GoodbyePlace("Bye bye"));
		clientFactory.getMain().addNavPlace( new ConnexionPlace());
	}
}
